﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace IntroApp
{
    public class SampleClient
    {
        private static readonly Func<int, int> HeavyProcess = i =>
        {
            Thread.Sleep(TimeSpan.FromSeconds(i));
            if (i % 2 == 1)
            {
                throw new ArgumentException("偶数のみです");
            }

            return i;
        };

        public IAsyncResult BeginCalc(int arg, AsyncCallback callback, object state)
        {
            return HeavyProcess.BeginInvoke(arg, callback, state);
        }

        public int EndCalc(IAsyncResult ar)
        {
            return HeavyProcess.EndInvoke(ar);
        }
    }
}
